import React from 'react';
import {connect} from "dva";
import {GlobalModelState} from "@/models/connect";
import LinkPermission from './LinkPermission';
import DefaultPermission from './DefaultPermission';
import ButtonPermission from './ButtonPermission';
import TabCardPermission from './TabCardPermission';
import ModalPermission from './ModalPermission';
import {FunctionVO} from "@/types/function";

export interface PermissionProps {
  functionKey?: string;
  functions?:FunctionVO[] |undefined;
}

class Permission extends React.Component<PermissionProps> {
  render() {
    const { functionKey,functions } = this.props;
    if(functionKey&&functions&&functions.some(item=>item.path===functionKey)){
      return this.props.children;
    }
    return null;
  }
}

export default connect(({
  global
}:{
  global: GlobalModelState;
}) => ({
  functions:global.profile.functions
}))(Permission);

export {
  DefaultPermission,
  ButtonPermission,
  LinkPermission,
  TabCardPermission,
  ModalPermission,
}
